package com.hurl.waguji.biz.collect;

import org.apache.log4j.Logger;

import com.hurl.waguji.base.DateService;
import com.hurl.waguji.base.dao.HibernateService;
import com.hurl.waguji.base.dataprocess.ProcessException;
import com.hurl.waguji.base.dataprocess.ProcessHelper;
import com.hurl.waguji.base.dataprocess.ProcessIdentifier;
import com.hurl.waguji.base.dataprocess.ProcessParams;
import com.hurl.waguji.base.dataprocess.ProcessResult;

public class CollectIdentifier extends ProcessIdentifier {
	public static final CollectIdentifier COLLECT = new CollectIdentifier();
	
	private static final Logger log = Logger.getLogger(CollectIdentifier.class);
	
	public CollectIdentifier() {
		super("sj.collect", "【数据处理】更新数据表");
	}

	@Override
	public ProcessResult execute(ProcessParams params) throws ProcessException {
		ProcessResult result = new ProcessResult(this);
		result.setStartTime(DateService.getCurrentTimeFromServer());
		try{
			log.debug("执行：更新股票基本资料！");
			new UpdateProfileProcess().execute();
			log.debug("执行：调用存储过程！");
			new ExecuteProcedureProcess(DateService.getLastTradingTimeFromWeb()).execute();
		}catch(Throwable t){
			log.error("错误："+t.getMessage());
			result.setEndTime(DateService.getCurrentTimeFromServer());
			result.setError(t);
			result.setSuccess(false);
			return result;
		}
		log.debug("执行成功！");
		result.setEndTime(DateService.getCurrentTimeFromServer());
		result.setSuccess(true);
		ProcessHelper.saveProcessResult(result, HibernateService.getDao());
		return result;
	}
}
